<template>
  <div class="liftexpertRegist pd30 propertyMaintenance">
    <div class="panelWrap">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>添加电梯专家</div>
        <!-- <i class="el-icon-close" @click="handleCloseDialogUpdate"></i> -->
      </div>
      <div class="con">
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>姓名：</span>
              <el-input v-model="liftexpert.name" class="input" placeholder="请输入机构名称" />
            </div>
            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr"><span class="mustval">*</span>身份证号：</span>
              <el-input v-model="liftexpert.idCardNo" class="input" placeholder="请输入机构简称" />
            </div>
          </div>
        </div>

        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>手机号：</span>
              <el-input v-model="liftexpert.phone" class="input" placeholder="请输入安全管理员" />
            </div>
            <div class="inputLable inputLable1 flex flexac m-l-60">
              <span class="name texttr"><span class="mustval">*</span>工作单位：</span>
              <el-input v-model="liftexpert.workPlace" class="input" placeholder="请输入安全管理员" />
            </div>
          </div>
        </div>

        <div class="con-row flex flexac pl ">
          <div class="inputLable inputLable2 flex flexac ">
            <span class="name texttr">行政区域：</span>
            <city :region-code="liftexpert.regionCode" />
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="inputLable inputLable2 flex ">
            <span class="name texttr p-t-10">专家照片：</span>
            <uploadImg />
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="inputLable wd100 inputLable1 flex ">
            <span class="name texttr">描述：</span>
            <textarea v-model="liftexpert.remark" class="markinfo" />
          </div>
        </div>

      </div>

      <div class="flex  footerBtn m-t-35">
        <el-button class="defaultbtn saveBtn" @click="handleSave">保存</el-button>
        <el-button class="defaultbtn clsoeBtn" @click="handleCloseDialogUpdate">关闭</el-button>
      </div>
    </div>
  </div>
</template>

<script>

import { liftexpertAdd } from '@/api/maintenance/role'
import { showNotice, successNotice, checkMobile } from '@/utils/toolclass'
import uploadImg from '@/components/uploadImg'
import city from '@/components/city'
export default {
  components: {
    uploadImg, city
  },
  props: {
    addFactory: {
      type: Object
    },
    isEdit: {
      type: Boolean
    }
  },
  data() {
    return {
      liftexpert: {
        id: '',
        name: '',
        idCardNo: '',
        phone: '',
        workPlace: '',
        remark: '',
        regionCode: {
          province: 430000, city: 430100, area: 430102
        }
      }

    }
  },
  watch: {
    editFactory: {
      deep: true, // 深度监听
      handler(newVal, oldVal) {
        console.log(newVal, oldVal)
      }
    }
  },
  created() {

  },
  methods: {
    handleImginfo(res) {

    },
    handleUpdate() {
      simpleViewUpdate(this.addFactory).then((res) => {
        if (res.code == '000000') {
          showNotice('success', '提示', '保存成功')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
        }
      })
    },
    handleSave() {
      if (this.liftexpert.name == '') {
        showNotice('error', '提示', '姓名为空')
        return
      }
      if (this.liftexpert.idCardNo == '') {
        showNotice('error', '提示', '身份证号为空')
        return
      }
      if (this.liftexpert.phone == '') {
        showNotice('error', '提示', '手机号为空')
        return
      }
      if (!checkMobile(this.liftexpert.phone)) {
        showNotice('error', '提示', '手机号手机格式不对')
        return
      }
      if (this.liftexpert.workPlace == '') {
        showNotice('error', '提示', '工作单位为空')
        return
      }
      this.handleliftexpertAdd(this.liftexpert)
    },
    handleCloseDialog() {
      console.log('子组件关闭')
      this.$emit('handleCloseDialog')
    },
    handleCloseDialogUpdate() {
      this.$emit('handleRefresh')
      this.$emit('handleCloseDialog')
    },
    handleliftexpertAdd(obj) {
      liftexpertAdd(obj).then((res) => {
        if (res.code == '000000') {
          showNotice('success', '提示', '保存成功!')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
        }
      })
    }
  }
}
</script>

<style rel='stylesheet/scss' lang='scss' scoped>
@import "@/styles/addtable.scss";
.inputLable .name {
  width: 140px !important;
  letter-spacing: 0px;
}
</style>
